<template>
  <j-modal
    :title="title"
    :draggable="true"
    :width="width"
    :visible="visible"
    switchFullscreen
    okText="确定"
    @ok="handleOk"
    @cancel="close"
    cancelText="关闭"
  >
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="versionId"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="rowSelection"
      @change="handleTableChange"
    >
    </a-table>
  </j-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { postAction } from '@/api/manage'
export default {
  name: 'Check',
  mixins: [JeecgListMixin],
  data() {
    return {
      title: '新增',
      width: 800,
      visible: false,
      disableSubmit: false,
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '模板名称',
          dataIndex: 'name',
          align: 'center'
        },
        {
          title: '发布时间',
          dataIndex: 'createTime',
          align: 'center'
        },
        {
          title: '模板类型',
          dataIndex: 'reportType_dictText',
          align: 'center'
        },
        {
          title: '当前版本',
          dataIndex: 'version',
          align: 'center'
        },
        {
          title: '当前版本',
          dataIndex: 'status_dictText',
          align: 'center',
        }
      ],
      queryParam: {},
      url: {
        list: '/sjtb/dataCollectionTemplateInfo/list',
        add: '/sjmx2/dataModelCollect/add'
      },
      selectedRowKeys: [],
      selectedRows: [],
      modelId: ''
    }
  },
  computed: {
    // 行选择
    rowSelection() {
      return {
        type: 'radio',
        selectedRowKeys: this.selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = [...selectedRowKeys]
          this.selectedRows = [...selectedRows]
        }
      }
    }
  },
  methods: {
    Check(modelId) {
      this.modelId = modelId
      this.loadData()
      this.visible = true
    },
    close() {
      this.modelId = ''
      this.selectedRowKeys = []
      this.selectedRows = []
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      // modelId collectId collectStatus collectVersion status
      let { id: collectId, status: collectStatus, version: collectVersion ,name:collectNm} = this.selectedRows[0]
      postAction(this.url.add, { modelId: this.modelId,collectNm, collectId, collectStatus, collectVersion, status: 0 })
        .then(res => {
          if (res.success) {
            this.close()
            this.$message.success(res.message)
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {})
    }
  }
}
</script>
